export default defineEventHandler(async (event) => {
  try {
    const body = await readBody(event);
    const { env = 'test' } = getQuery(event); // 默认为测试环境
    
    if (!body) {
      return {
        code: 400,
        message: '缺少请求体参数'
      }
    }

    const config = useRuntimeConfig();
    const baseUrl = env === 'prod' 
      ? config.public.soServiceUrlProd 
      : config.public.soServiceUrlTest;

    const response = await $fetch(`${baseUrl}/service/so_order_queryCustomerOrderDetails`, {
      method: 'POST',
      body: body
    });
    
    return {
      code: 200,
      data: typeof response === 'string' ? JSON.parse(response) : response
    }
    
  } catch (e) {
    return {
      code: 500,
      message: (e instanceof Error ? e.message : 'Internal Server Error')
    }
  }
})
